import 'package:flutter/material.dart';
import 'dart:math';
extension HexColor on Color {
  /// String is in the format "aabbcc" or "ffaabbcc" with an optional leading "#".
  static Color fromHex(String hexString) {
    final buffer = StringBuffer();
    if (hexString.length == 6 || hexString.length == 7) buffer.write('ff');
    buffer.write(hexString.replaceFirst('#', ''));
    return Color(int.parse(buffer.toString(), radix: 16));
  }

  static Color hexColor(int hex, {double alpha = 1}) {
    if (alpha < 0) {
      alpha = 0;
    } else if (alpha > 1) {
      alpha = 1;
    }
    return Color.fromRGBO((hex & 0xFF0000) >> 16, (hex & 0x00FF00) >> 8,
        (hex & 0x0000FF) >> 0, alpha);
  }



  /// Prefixes a hash sign if [leadingHashSign] is set to `true` (default is `true`).
  String toHex({bool leadingHashSign = true}) => '${leadingHashSign ? '#' : ''}'
      '${alpha.toRadixString(16).padLeft(2, '0')}'
      '${red.toRadixString(16).padLeft(2, '0')}'
      '${green.toRadixString(16).padLeft(2, '0')}'
      '${blue.toRadixString(16).padLeft(2, '0')}';
}

class Colours {

  static Color getRandomColor({int r = 255, int g = 255, int b = 255, a = 255}) {
    if (r == 0 || g == 0 || b == 0) return Colors.black;
    if (a == 0) return Colors.white;
    return Color.fromARGB(
      a,
      r != 255 ? r : Random.secure().nextInt(r),
      g != 255 ? g : Random.secure().nextInt(g),
      b != 255 ? b : Random.secure().nextInt(b),
    );
  }

  static Color randomColor = Color.fromRGBO(Random().nextInt(256), Random().nextInt(256), Random().nextInt(256), 1);

  static const Color app_main = Color(0xFFF85959);
  static const Color app_bg = Color(0xfff4f4f4);
  static const Color session_selected_bg = Color(0xFFEDEDED);

  static const Color app_red = Color(0xFFF85959);
  static const Color app_grey = Color(0xFFD1D1D1);
  static const Color chart_red = Color(0xFFE78887);
  static const Color chart_green = Color(0xFF87D6AA);
  static const Color invalid_grey = Color(0xFFD9D9D9);

  static const Color transparent_80 = Color(0x80000000); //<!--204-->
  static const Color white_19 = Color(0X19FFFFFF);


  static const Color app_black = Color(0xFF262626);
  static const Color text_dark = Color(0xFF333333);
  static const Color text_normal = Color(0xFF262626);
  static const Color text_grey = Color(0xFF8C8C8C);

  static const Color divider = Color(0xFFD9D9D9);
  static const Color content_red = Color(0xFFFA5151);

  static const Color gray_e1 = Color(0xFFE1E1E1); //E1
  static const Color gray_ae = Color(0xFFaeaeae); //ae
  static const Color gray_33 = Color(0xFF333333); //51
  static const Color gray_66 = Color(0xFF666666); //102
  static const Color gray_f6 = Color(0xFFF6F6F6); //102
  static const Color gray_99 = Color(0xFF999999); //153
  static const Color common_orange = Color(0XFFFC9153); //252 145 83
  static const Color gray_ef = Color(0XFFEFEFEF); //153
  static const Color app_main_orange = Color(0XFFED6C00); //153

  static const Color gray_f0 = Color(0xfff0f0f0); //<!--204-->
  static const Color gray_f5 = Color(0xfff5f5f5); //<!--204-->
  static const Color gray_cc = Color(0xffcccccc); //<!--204-->
  static const Color gray_ce = Color(0xffcecece); //<!--206-->
  static const Color green_1 = Color(0xff009688); //<!--204-->
  static const Color green_62 = Color(0xff626262); //<!--204-->
  static const Color green_e5 = Color(0xffe5e5e5); //<!--204-->

  static const Color green_de = Color(0xffdedede);
  static const Color k59 = Color(0xff595959);
  static const Color kf6 = Color(0xfff6f6f6);
  
  
  static const Color group_color_1 = Color(0xFF82BD40);
  static const Color group_color_2 = Color(0xFFF6A50F);
  static const Color group_color_3 = Color(0xFF06BFA6);
  static const Color group_color_4 = Color(0xFF2095F3);
  static const Color group_color_5 = Color(0xFFE53935);
  static const Color group_color_6 = Color(0xFF9C27B0);
  static const Color group_color_7 = Color(0xFF278BB0);
  static const Color group_color_8 = Color(0xFF27B074);
  static const Color group_color_9 = Color(0xFFB07427);
  static const Color group_color_10 = Color(0xFF3C43EF);
  
}

Map<String, Color> circleAvatarMap = {
  'A': Colors.blueAccent,
  'B': Colors.blue,
  'C': Colors.cyan,
  'D': Colors.deepPurple,
  'E': Colors.deepPurpleAccent,
  'F': Colors.blue,
  'G': Colors.green,
  'H': Colors.lightBlue,
  'I': Colors.indigo,
  'J': Colors.blue,
  'K': Colors.blue,
  'L': Colors.lightGreen,
  'M': Colors.blue,
  'N': Colors.brown,
  'O': Colors.orange,
  'P': Colors.purple,
  'Q': Colors.black,
  'R': Colors.red,
  'S': Colors.blue,
  'T': Colors.teal,
  'U': Colors.purpleAccent,
  'V': Colors.black,
  'W': Colors.brown,
  'X': Colors.blue,
  'Y': Colors.yellow,
  'Z': Colors.grey,
  '#': Colors.blue,
};

Map<String, Color> themeColorMap = {
  'gray': Colours.gray_33,
  'blue': Colors.blue,
  'blueAccent': Colors.blueAccent,
  'cyan': Colors.cyan,
  'deepPurple': Colors.deepPurple,
  'deepPurpleAccent': Colors.deepPurpleAccent,
  'deepOrange': Colors.deepOrange,
  'green': Colors.green,
  'indigo': Colors.indigo,
  'indigoAccent': Colors.indigoAccent,
  'orange': Colors.orange,
  'purple': Colors.purple,
  'pink': Colors.pink,
  'red': Colors.red,
  'teal': Colors.teal,
  'black': Colors.black,
};

class GroupColor {
  static Color color(int value) {
    switch(value % 10) {
      case 1:
        return Colours.group_color_1;
      case 2:
        return Colours.group_color_2;
      case 3:
        return Colours.group_color_3;
      case 4:
        return Colours.group_color_4;
      case 5:
        return Colours.group_color_5;
      case 6:
        return Colours.group_color_6;
      case 7:
        return Colours.group_color_7;
      case 8:
        return Colours.group_color_8;
      case 9:
        return Colours.group_color_9;
      case 10:
        return Colours.group_color_10;
      default:
        return Colors.red;
    }
  }
}